package com.aaa.ssm.controller;



import com.aaa.ssm.entity.*;
import com.aaa.ssm.service.OrderService;
import com.aaa.ssm.service.RegistrationService;
import com.aaa.ssm.service.SchedulingService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author wjz
 * 2023/10/19
 */
@RestController
@RequestMapping("/regi")
public class RegistrationController {


    @Resource
    private RegistrationService registrationService;
    @Resource
    private OrderService orderService;



    /**
     * @return 前台挂号添加
     */
    @PostMapping
    public Result insert(@RequestBody Registration registration) {

      return Result.success(registrationService.add(registration));
    }

    @GetMapping("queryByIn")
    @ResponseBody
    public Result login(String sname, String card, HttpSession session){
  /*      Registration registration = registrationService.queryByIn(sname, card);
        if (registration!=null){
            session.setAttribute("userInfo",registration);
        }*/
        return Result.success(registrationService.queryByIn(sname, card));
    }

    @PostMapping("getNativeCodeUrl")
    public Result getNativeCodeUrl(@RequestBody Registration registration){
        return Result.success(orderService.getNativeByOrder(registration));
    }
    @PostMapping("queryByParam")
    public Result queryByParame(@RequestBody Registration registration){
        return Result.success(registrationService.queryByParam(registration));
    }
    @DeleteMapping("delete")
    public Result delete(String id){
        return Result.success(registrationService.delete(id));
    }
    @PostMapping("queryByPage")
    //@ResponseBody
    public Result queryByPage(@RequestBody Page<Registration> page){
        return Result.success(registrationService.queryByPage(page));
    }
    @PutMapping("updateId")
    public Result updateId(String id){
        return Result.success(registrationService.updateId(id));
    }

    @GetMapping("queryTreeDataByUserName")
    public Result  queryTreeDataByUserId(HttpSession session){
        String name = ((SysCareer) session.getAttribute("userInfo")).getName();


        System.out.println(name+"++++++++++++++++++++++++++++++++");
        return Result.success(registrationService.queryTreeDataByUserName(name));
    }
    @PutMapping("updateBy")
    //@ResponseBody
    private Result update(@RequestBody Registration registration){
        return Result.success(registrationService.updateBy(registration));
    }
}
